<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@include file="../../util/taglib.jsp" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>批量添加权限</title>
  </head>
  <body>
      <div id="editPermissionPage"  class="easyui-layout"  data-options="fit:'true'">
		<div class="permissionTree" data-options="region:'west',split:true,title:'导航树'" title="West" style="width:240px;padding:3px">
			
		</div>
		<div data-options="region:'center',title:'表单操作'" title="Center">
		    <div class="form-Container">
            <form action="${pageContext.request.contextPath}/permission/editAllPermission.do"  id="dataForm" class="grayForm" method="post">
            <input type="hidden" name="curCompanyUUID" value="${param.companyUUID }" />
                <table>
                    <tr>
                        <td style="text-align: right;">
                            <input type="button" value="新增一栏"    id="createRow" />
                        </td>
                    </tr>
                </table>
                <table>
                   <tr>
                        <td style="width:65px"><label for="parentName" style="width:65px;">上级权限:</label></td>
                        <td style="line-height:20px;">
                          <input type="hidden" name="parentUUID"  id="parentUUID" value="" >
	                      <input type="text"  name="parentName"  style="width:390px;background-color: #F0F0F0" required readonly="readonly"/>
                        </td>
                    </tr>
                </table>
                <table id="contentTable">
                    <tr>
                        <td style="width:65px"><label for="psmName" style="width:65px;">权限名称:</label></td>
                        <td style="line-height:20px;"><input type="text"  name="psmName"/></td>
                        <td style="width:65px"><label for="psmType" style="width:65px">链接类型:</label></td>
                        <td style="line-height:20px;width:60px;">
                          <select name="psmType" style="width:80px;margin-right: 5px">
                             <option value="1">普通链接</option>
                             <option value="2">增加</option>
                             <option value="3">删除</option>
                             <option value="4">修改</option>
                             <option value="5">审批</option>
                             <option value="6">恢复</option>
                             <option value="7">彻底删除</option>
                             <option value="8">文件导入</option>
                          </select>
                        </td>
                        <td style="width:65px"><label for="psmUrl" style="width:65px">权限地址:</label></td>
                        <td style="line-height:20px;"><input type="text"  name="psmUrl"/></td>
                        <td style="width:50px"><label for="psmIcon" style="width:65px">图标:</label></td>
                        <td style="line-height:20px;"><input type="text"  name="psmIcon"/></td>
                    </tr>
                    <tr>
                        <td style="width:65px"><label for="psmName" style="width:65px;">权限名称:</label></td>
                        <td style="line-height:20px;"><input type="text"  name="psmName"/></td>
                        <td style="width:65px"><label for="psmType" style="width:65px">链接类型:</label></td>
                        <td style="line-height:20px;width:60px;">
                          <select name="psmType" style="width:80px;margin-right: 5px">
                             <option value="1">普通链接</option>
                             <option value="2">增加</option>
                             <option value="3">删除</option>
                             <option value="4">修改</option>
                             <option value="5">审批</option>
                             <option value="6">恢复</option>
                             <option value="7">彻底删除</option>
                             <option value="8">文件导入</option>
                          </select>
                        </td>
                        <td style="width:65px"><label for="psmUrl" style="width:65px">权限地址:</label></td>
                        <td style="line-height:20px;"><input type="text"  name="psmUrl"/></td>
                        <td style="width:50px"><label for="psmIcon" style="width:65px">图标:</label></td>
                        <td style="line-height:20px;"><input type="text"  name="psmIcon"/></td>
                    </tr>
                    <tr>
                        <td style="width:65px"><label for="psmName" style="width:65px;">权限名称:</label></td>
                        <td style="line-height:20px;"><input type="text"  name="psmName"/></td>
                        <td style="width:65px"><label for="psmType" style="width:65px">链接类型:</label></td>
                        <td style="line-height:20px;width:60px;">
                          <select name="psmType" style="width:80px;margin-right: 5px">
                             <option value="1">普通链接</option>
                             <option value="2">增加</option>
                             <option value="3">删除</option>
                             <option value="4">修改</option>
                             <option value="5">审批</option>
                             <option value="6">恢复</option>
                             <option value="7">彻底删除</option>
                             <option value="8">文件导入</option>
                          </select>
                        </td>
                        <td style="width:65px"><label for="psmUrl" style="width:65px">权限地址:</label></td>
                        <td style="line-height:20px;"><input type="text"  name="psmUrl"/></td>
                        <td style="width:50px"><label for="psmIcon" style="width:65px">图标:</label></td>
                        <td style="line-height:20px;"><input type="text"  name="psmIcon"/></td>
                    </tr>
                    <tr>
                        <td style="width:65px"><label for="psmName" style="width:65px;">权限名称:</label></td>
                        <td style="line-height:20px;"><input type="text"  name="psmName"/></td>
                        <td style="width:65px"><label for="psmType" style="width:65px">链接类型:</label></td>
                        <td style="line-height:20px;width:60px;">
                          <select name="psmType" style="width:80px;margin-right: 5px">
                             <option value="1">普通链接</option>
                             <option value="2">增加</option>
                             <option value="3">删除</option>
                             <option value="4">修改</option>
                             <option value="5">审批</option>
                             <option value="6">恢复</option>
                             <option value="7">彻底删除</option>
                             <option value="8">文件导入</option>
                          </select>
                        </td>
                        <td style="width:65px"><label for="psmUrl" style="width:65px">权限地址:</label></td>
                        <td style="line-height:20px;"><input type="text"  name="psmUrl"/></td>
                        <td style="width:50px"><label for="psmIcon" style="width:65px">图标:</label></td>
                        <td style="line-height:20px;"><input type="text"  name="psmIcon"/></td>
                    </tr>
                </table>
                <table>
                    <tr>
                        <td style="text-align: center;">
                            <input type="button" value="提交数据" name="submitData"  />
                            <input type="button" value="关闭" name="close" />
                        </td>
                    </tr>
                </table>
                <div id="confirmMsg"></div>
            </form>
          </div>
		</div>
	  </div>
	   <script type="text/javascript">
        var baseId = "#editPermissionPage ";
        $(document).ready(function () {
        	//加载树
        	$('#editPermissionPage .permissionTree').tree({    
			    url:getBasePath()+"permission/getPermissionTree.do",
			    method:'post',
			    animate:true,
			    lines:true,
			    onClick:function(node){
			    	$(baseId+"input[name='parentUUID']").val(node.id);
			    	$(baseId+"input[name='parentName']").val(node.text);
			    }
			});  
        	
        	$(baseId+"input[name='close']").click(function () {
        		   $("#editDataFormArea").window("close");
           	})
        	
        	var rules = {}
        	var messages = {}
        	messages = {
        	    parentName:"请从左边选择你的上级权限！",
            };
        	
        	var validateForm = $(baseId+"#dataForm").validate({
                debug:true,
                rules:rules,
                messages:messages
            });
        	
        	//表格新增一行
        	$(baseId+" #createRow").click(function(){
        		var firstTrDom = $(baseId+" #contentTable tr:first");
        		var trLength = $(baseId+" #contentTable tr").length+1;
        		var rowHtml = firstTrDom.html();
        		rowHtml = "<tr>"+rowHtml+"</tr>";
        		$(baseId+" #contentTable").append(rowHtml);
        	})
        	
        	//表格移除
        	$(baseId+" #removeRow").click(function(){
        		var trLength = $(baseId+" #contentTable tr").length
        		var checkedLength = $(baseId+" #contentTable input:checked").length;
        		if(trLength>checkedLength){
        			$(baseId+" #contentTable :checkbox").each(function(i){
            			if(checked=="checked"){
            				$(this).parent().parent().remove();
            			}
            		})
        		}else{
        			$.messager.alert('我的消息','不可全部移除,至少保留一行！','info');
        		}
        	})
        	
            //提交数据到服务器
            $(baseId+" input[name='submitData']").click(function () {
            	//提交表单进行验证
                var actionUrl = $(baseId+" #dataForm").attr("action");
            	var permissionList = [];
            	var parentUUID = $(baseId+" input[name='parentUUID']").val();
            	var parentName = $(baseId+" input[name='parentName']").val();
            	
            	$(baseId+" input[name='psmName']").each(function(i){
            		if($(this).val()!=""){
            			var permission = new Object();
                		permission.parentUUID = parentUUID;
                		permission.parentName = parentName;
                		permission.psmIcon = $(baseId+" input[name='psmIcon']:eq("+i+")").val();
                		permission.psmName = $(this).val();
                		permission.psmUrl = $(baseId+" input[name='psmUrl']:eq("+i+")").val();
                		permission.psmType = $(baseId+" input[name='psmType']:eq("+i+")").val();
                		permission.permissionDesc = permission.psmName;
                		permissionList.push(permission);
            		}
            	})
            	var formData = $.toJSON(permissionList);
            	//提交表单进行验证
            	$("#dataForm").submit();
                var validateFlag = validateForm.form();
                if(validateFlag){
                	$.post(actionUrl,{formData:formData},function(data){
                		if(data.code=="00"){
           				  $.messager.confirm('操作确认',data.msg+',请确认是否继续操作？', function(flag){
           					  if(flag){
           						  $("#editDataFormArea").window("close");
           						  tableObject.treegrid('reload');
           					  }
           				  });
           			    }else{
           				   $.messager.alert('操作提示',data.message,'error');
           			    }
          		    },"json");
                }
            });
        });
    </script>
  </body>
</html>
